﻿using ChangchunPublicInterfacs;
using ChangchunPulbicServicesImp;
using CommunityToolkit.Diagnostics;
using EntityAccessImp;
using EntityAccessInterfaces;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PublicModels;
using PublicModels.APIObjs;
using PublicModels.Draft;
using PublicModels.Eums;
using PublicModels.Helpers;
using SpatialLite.Core.Geometries;
using SpatialLite.Core.IO;
using System.Net.Http;
using Test;
using TSP;

var Services = new ServiceCollection();

Services.AddHttpClient();
Services.AddSqlSugarSetup(BasicConfigServices.AdminConnectionString);

Services.AddScoped<IAuxiliaryFunction, AuxiliaryFunctionServices>();
Services.AddScoped<IPoiQuery, PoiQueryServices>();
Services.AddScoped<ITravelSubject, TravelSubjectServices>();
Services.AddScoped<IUserAccountServices, UserAccountServices>();

Services.AddScoped<IAnnotationServices, AnnotationServices>();
Services.AddScoped<IConfigServices, ConfigServices>();
Services.AddScoped<IDraftServices, DraftServices>();
Services.AddScoped<IUserServices, UserServices>();

using (var sp = Services.BuildServiceProvider())
{
    //var geos = new List<Geometry>()
    //{
    //    WktReader.Parse("POINT (125.367976 43.870846)"),
    //    WktReader.Parse("LINESTRING (125.197226 43.730929, 125.307609 43.687972, 125.522628 43.696733)"),
    //    WktReader.Parse("POLYGON ((125.530677 43.957295, 125.731322 43.790101, 125.615764 43.835481, 125.530677 43.957295))"),
    //};
    //var draft = new Draft()
    //{
    //    OwnerID = 2,
    //    Lat = 40,
    //    Lng = 120,
    //    Zoom = 12,
    //    Name = "测试2",
    //};
    //draft.AddAnnotations(geos);
    //var t = sp.GetRequiredService<IDraftServices>();
    //Console.WriteLine(await t.AddDraftAsync(draft));

    //var t = sp.GetRequiredService<IAuxiliaryFunction>();
    //var r = await t.WeatherForecastAsync(new Point(112.461742, 34.620714));
    //Console.WriteLine(r.Sunny);

    using (SqlConnection conn = new SqlConnection("Server=服务器名;DataBase=数据库名称;Trusted_Connection=SSPI"))
    {
        conn.Open();

        string sql = "select * from 表名 ";
        SqlCommand sqlcomm = new SqlCommand(sql, conn);

        SqlDataReader reader = sqlcomm.ExecuteReader();
        int id = 0, channel = 0;

        while (reader.Read())
        {
            id = (int)reader["id"];
            channel = (Int32)reader["channel"];
        }

        reader.Close();
        conn.Close();
    }
}